/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.BasicBehaviors;
// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.*;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.model.xml.XMLUtility;

import edu.pku.sei.modeler.model.uml.Kernel.Parameter;
import edu.pku.sei.modeler.model.uml.Interfaces.BehavioredClassifier;
import edu.pku.sei.modeler.model.uml.Kernel.Constraint;
import edu.pku.sei.modeler.model.uml.Kernel.Constraint;

import edu.pku.sei.modeler.model.uml.Kernel.UMLClass;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;

/**
 * @generated
 *
 */
public class Behavior extends UMLClass implements IBehavior {
	// attributes
	
	protected boolean isReentrant;
	
	
	
	
	// references
	
	protected MetaTypedList ownedParameter;
	
	protected MetaTypedList redefinedBehavior;
	
	protected MetaTypedList context;
	
	protected MetaTypedList precondition;
	
	protected MetaTypedList postcondition;
	
	
	
	// getters & setters for attributes
	
	@MethodProperty(
			id = "BEHAVIOR_ISREENTRANT",
			catalog = "Model",
			name = ModelPackage.BEHAVIOR_ISREENTRANT,
			setter = "setisReentrant"
			)
	
	public boolean getIsReentrant() {
		return isReentrant;
	}
	public void setIsReentrant(boolean newIsReentrant) {
		boolean oldisReentrant = isReentrant;
		isReentrant = newIsReentrant;
		firePropertyChange(ModelPackage.BEHAVIOR_ISREENTRANT, oldisReentrant, newIsReentrant);
	}
	
	// getters for references
	
	public MetaTypedList getOwnedParameter() {
		if(ownedParameter == null) {
			ownedParameter = new MetaTypedList(Parameter.class, this, ModelPackage.BEHAVIOR_OWNEDPARAMETER);
		}
		return ownedParameter;
	}
	
	public MetaTypedList getRedefinedBehavior() {
		if(redefinedBehavior == null) {
			redefinedBehavior = new MetaTypedList(Behavior.class, this, ModelPackage.BEHAVIOR_REDEFINEDBEHAVIOR);
		}
		return redefinedBehavior;
	}
	
	public MetaTypedList getContext() {
		if(context == null) {
			context = new MetaTypedList(BehavioredClassifier.class, this, ModelPackage.BEHAVIOR_CONTEXT);
		}
		return context;
	}
	
	public MetaTypedList getPrecondition() {
		if(precondition == null) {
			precondition = new MetaTypedList(Constraint.class, this, ModelPackage.BEHAVIOR_PRECONDITION);
		}
		return precondition;
	}
	
	public MetaTypedList getPostcondition() {
		if(postcondition == null) {
			postcondition = new MetaTypedList(Constraint.class, this, ModelPackage.BEHAVIOR_POSTCONDITION);
		}
		return postcondition;
	}
	
	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.BEHAVIOR_ISREENTRANT, isReentrant);
		
		// references
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.BEHAVIOR_OWNEDPARAMETER, ownedParameter);
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.BEHAVIOR_REDEFINEDBEHAVIOR, redefinedBehavior);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.BEHAVIOR_CONTEXT, context);		
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.BEHAVIOR_PRECONDITION, precondition);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.BEHAVIOR_POSTCONDITION, postcondition);
		
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes
		
		isReentrant = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.BEHAVIOR_ISREENTRANT);
		
		// references
		
		this.getOwnedParameter().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.BEHAVIOR_OWNEDPARAMETER));
		
		this.getRedefinedBehavior().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.BEHAVIOR_REDEFINEDBEHAVIOR, this));
		
		this.getContext().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.BEHAVIOR_CONTEXT, this));
		
		this.getPrecondition().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.BEHAVIOR_PRECONDITION));
		
		this.getPostcondition().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.BEHAVIOR_POSTCONDITION));
		
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		
		// references
		
		else if(ModelPackage.BEHAVIOR_REDEFINEDBEHAVIOR.equals(featureID)) {
			getRedefinedBehavior().add(value);
		}
		
		else if(ModelPackage.BEHAVIOR_CONTEXT.equals(featureID)) {
			getContext().add(value);
		}
		
		else
			super.dynamicSet(featureID, value);
	}
}
 
 
 
 
 